package com.coin.gateway.config;

import org.springframework.context.annotation.*;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.*;
import org.springframework.web.util.pattern.PathPatternParser;

/**
 * @Auther: 李 力
 * @Date: 2025/6/10
 * @Description: com.coin.gateway.config
 * @version: 1.0
 */
@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*"); // 允许跨域访问的方法
        config.addAllowedOrigin("*"); // 允许跨域访问的域
        config.addAllowedHeader("*"); // 允许跨域的头
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config); // 所有路径都支持跨域
        return new CorsWebFilter(source);
    }
}
